import setting
import myTool
import baiduData as bdd
import json

def getDistance(start,end,**dictargs):
    # 默认追
    # way="drive",coord="bd09ll",ret_coord="bd09ll",tactics="10"):
    the_url = getBaiduURL(dictargs["way"] if "way" in dictargs else "drive")
    the_results = {}
    if the_url:
        the_url += (
            bdd.BAIDU_ORIGIN+start+
            bdd.BAIDU_DESTINATION+end+
            bdd.BAIDU_CHACK_AK+bdd.BAIDU_AK_SERVER+
            (dictargs["coord"] if "coord" in dictargs else "")+
            (dictargs["ret_coord"] if "ret_coord" in dictargs else "")+
            (dictargs["tactics"] if "tactics" in dictargs else "")
        )
        the_results = the_url
    return the_results

def getBaiduURL(way="drive"):
    the_url = ""
    if way=="drive":
        the_url = bdd.BAIDU_URL_DRIVE
    elif way=="ride":
        the_url = bdd.BAIDU_URL_RIDE
    elif way=="walk":
        the_url = bdd.BAIDU_URL_WALK
    elif way=="bus":
        the_url = bdd.BAIDU_URL_BUS
    return the_url

if __name__ == "__main__":
    # result = getDistance("30.263411,120.166516","30.316393,120.354855")
    result = getDistance("18.33,-65.65","18.22,-66.03")
    print(result)
    
    print(myTool.getJson(json.loads(myTool.getURLData(result))))
